********************************************************************************************************************************
***   Replication file for:                                                                                                  ***
***   Rafiee Rad, S., Braun, S. T., and Roy, O. (2023). Anchoring as a Structural Bias of Deliberation.					     ***
***   							                                                                                             ***
***   SCRIPT: 		1_analysis_agent_level.do																				 ***	
***   PURPOSE: 		script for analysis of model-run level data																 ***
***   REPLICATES:	Figure:	3																								 ***					
***					Table:  3, A-8, A-9																						 ***
********************************************************************************************************************************

* Preamble (unnecessary when executing run.do)
run "$anchoring/scripts/programs/_config.do"

***************
* Code begins
***************

******************
*** Read in model-run level data

use "$anchoring/processed/data_model_run_level.dta.dta", clear


*** Replicate Figure 3 (Average distance to single-peakedness and single-plateauedness by measure)

graph bar (mean) prox_single_peak_ini (mean) prox_single_peak_dp (mean) prox_single_peak_ks (mean) prox_single_peak_cs, legend(row(1) order(1 "Initial" 2 "DP" 3 "KS" 4 "CS") position(6)) graphregion(color(white)) bar(1, fcolor(gs0) lcolor(black)) bar(2, fcolor(gs6) lcolor(black)) bar(3, fcolor(gs12) lcolor(black)) bar(4, fcolor(gs16) lcolor(black)) ylabel(0.0(0.1)0.4, nogrid) 
graph export "$anchoring/results/figures/Fig3a.eps", replace

graph bar (mean) prox_single_plateau_ini (mean) prox_single_plateau_dp (mean) prox_single_plateau_ks (mean) prox_single_plateau_cs, legend(row(1) order(1 "Initial" 2 "DP" 3 "KS" 4 "CS") position(6)) graphregion(color(white)) bar(1, fcolor(gs0) lcolor(black)) bar(2, fcolor(gs6) lcolor(black)) bar(3, fcolor(gs12) lcolor(black)) bar(4, fcolor(gs16) lcolor(black)) ylabel(0.0(0.2)1.0, nogrid)
graph export "$anchoring/results/figures/Fig3b.eps", replace

* Two-sided t-tests (unreported)

ttest prox_single_peak_ini = prox_single_peak_dp
ttest prox_single_peak_ini = prox_single_peak_ks
ttest prox_single_peak_ini = prox_single_peak_cs

ttest prox_single_plateau_ini = prox_single_plateau_dp
ttest prox_single_plateau_ini = prox_single_plateau_ks
ttest prox_single_plateau_ini = prox_single_plateau_cs


*** Replicate Tables 3, A-8, A-9 (Anchoring and distance to single-peakedness & single-plateauedness)

** Generate anchoring measures

* Continuous (-1-0)
foreach x in dp ks cs{
gen anchoring_strength_`x' =  -(distance_first_`x' / max_distance_`x')
}

* Boolean (0/1)
foreach x in dp ks cs{
gen d_anchoring_`x' = 0
replace d_anchoring_`x' = 1 if min_distance_`x' == distance_first_`x'
}

* Regressions

foreach x in dp ks cs{
preserve

drop if d_`x'transitive == 0


areg prox_single_peak_`x' anchoring_strength_`x', robust absorb(groupsize)
est store col1 
areg prox_single_peak_`x' d_anchoring_`x', robust absorb(groupsize) 
est store col2
 
areg prox_single_plateau_`x' anchoring_strength_`x', robust absorb(groupsize) 
est store col3
areg prox_single_plateau_`x' d_anchoring_`x', robust absorb(groupsize)
est store col4


outreg2 [col1 col2 col3 col4] using "$anchoring/results/tables/table_sp_`x'.tex", dec(3) replace

restore
}

* Add additional controls (unreported)

* Generate variable for alignment with first speakers prefernces
gen share_agents_first_pref = (freqvoteag1-1) / (groupsize-1)
label var share_agents_first_pref "Share of agents (other than the first speaker) that share first speaker's preference"

* Herfindahl index for similarity of preferences
gen preference_similarity = (numvotes0 / groupsize)^2 
forvalues i = 1(1)12{
	replace preference_similarity = preference_similarity + (numvotes`i' / groupsize)^2
}
label var preference_similarity "Herfindahl index for preference similarity"

foreach x in dp ks cs{
preserve

drop if d_`x'transitive == 0

areg prox_single_peak_`x' anchoring_strength_`x' preference_similarity share_agents_first_pref prox_single_peak_ini, robust absorb(groupsize)
areg prox_single_peak_`x' d_anchoring_`x' preference_similarity share_agents_first_pref prox_single_peak_ini, robust absorb(groupsize) 
 
areg prox_single_plateau_`x' anchoring_strength_`x' preference_similarity share_agents_first_pref prox_single_plateau_ini, robust absorb(groupsize) 
areg prox_single_plateau_`x' d_anchoring_`x' preference_similarity share_agents_first_pref prox_single_plateau_ini, robust absorb(groupsize) 

restore
}






*** EOF